package com.richapp.launcher.serialport.gateway.command;

import com.richapp.launcher.serialport.gateway.ControlInstructionMessage;
import com.richapp.launcher.serialport.gateway.GatewaytConstant;
import com.richapp.launcher.serialport.gateway.GatewayServer;

import android.util.Log;

public class RestCmd extends BasicCommand {
	
	private static RestCmd resetCmd = null;
	
	private RestCmd() {
		
	}
	
	public static RestCmd getInstance(){
		if(resetCmd == null){
			resetCmd = new RestCmd();
		}
		return resetCmd;
	}
    
	//复位
	public void restAllCmd() {
		ControlInstructionMessage cim = new ControlInstructionMessage(null,null,null,null);
		cim.setHexInstruction(GatewaytConstant.INSTRUCTION_RESET_ALL_STR);
		cim.setInstructionFlag(GatewaytConstant.INSTRUCTION_FLAG_RESET_ALL);
		GatewayServer.getInstance().writeMessage(cim);
	}
	
	//单个复位 PacketHead + ID + Number + Way + AddDevice + Reset + Upgrade + Switch + Adjust + Query + Read + SceneSwitch_high+SceneSwitch_low+ checkCode()
	public void restOneCmd(String cpuBoxId,String deviceId, String deviceNumber,String way){
		this.ID = deviceId;
		this.Number = deviceNumber;
		this.Reset = "6F";
        this.Way = way;
		ControlInstructionMessage cim = new ControlInstructionMessage(cpuBoxId,deviceId,deviceNumber,way);
		cim.setHexInstruction(combinationCMD());
		cim.setInstructionFlag(GatewaytConstant.INSTRUCTION_FLAG_RESET_ONE);
		GatewayServer.getInstance().writeMessage(cim);
	}

	public void deanRestOneCmd(String cpuBoxId,String deviceId, String deviceNumber){
		this.ID = deviceId;
		this.Number = deviceNumber;
		this.Reset = "6F";
		ControlInstructionMessage cim = new ControlInstructionMessage(cpuBoxId,deviceId,deviceNumber);
		cim.setHexInstruction(getResetOnecombinationCMD());
		cim.setInstructionFlag(GatewaytConstant.INSTRUCTION_FLAG_RESET_ONE);
		GatewayServer.getInstance().writeMessage(cim);
	}

	@Override
	public void analyticalCmd(String cmd) {
        Log.v("rq", "复位  cmd "+cmd);
	}

}
